<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>cmp</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_092">&nbsp;</a>NAME</h4><blockquote>
cmp - compare two files
</blockquote><h4><a name = "tag_001_014_093">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

cmp <b>[</b> -l | -s <b>] </b><i>file1 file2</i>
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_094">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>cmp</i>
utility compares two files.
The
<i>cmp</i>
utility will write no output
if the files are the same.
Under default options,
if they differ, it will write to standard output
the byte and line number at
which the first difference occurred.
Bytes and lines will be numbered beginning with 1.
</blockquote><h4><a name = "tag_001_014_095">&nbsp;</a>OPTIONS</h4><blockquote>
The
<i>cmp</i>
utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .
<p>
The following options are supported:
<dl compact>

<dt><b>-l</b>
<dd>(Lower-case ell.)
Write the byte number (decimal) and the
differing bytes (octal) for each difference.

<dt><b>-s</b>
<dd>Write nothing for differing files;
return exit status only.

</dl>
</blockquote><h4><a name = "tag_001_014_096">&nbsp;</a>OPERANDS</h4><blockquote>
The following operands are supported:
<dl compact>

<dt><i>file1</i><dd>A pathname of the first file to be compared.
If
<i>file1</i>
is "-", the standard input will be used.

<dt><i>file2</i><dd>A pathname of the second file to be compared.
If
<i>file2</i>
is "-", the standard input will be used.

</dl>
<p>
If both
<i>file1</i>
and
<i>file2</i>
refer to
standard input or refer to the same FIFO special, block special or
character special file, the results are undefined.
</blockquote><h4><a name = "tag_001_014_097">&nbsp;</a>STDIN</h4><blockquote>
The standard input will be used only if
the
<i>file1</i>
or
<i>file2</i>
operand refers to standard input.
See the INPUT FILES section.
</blockquote><h4><a name = "tag_001_014_098">&nbsp;</a>INPUT FILES</h4><blockquote>
The input files can be any file type.
</blockquote><h4><a name = "tag_001_014_099">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>cmp</i>:
<dl compact>

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.

<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.

<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data as
characters (for example, single- as opposed to multi-byte characters
in arguments).

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error
and informative messages written to standard output.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
</dl>
</blockquote><h4><a name = "tag_001_014_100">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_101">&nbsp;</a>STDOUT</h4><blockquote>
In the POSIX locale,
results of the comparison will be written to standard output.
When no options are used, the format will be:
<p><code>
<pre>
<tt>"%s&nbsp;%s&nbsp;differ:&nbsp;char&nbsp;%d,&nbsp;line&nbsp;%d\n"</tt>, <i>file1</i>,
<i>file2</i>,
&lt;<i>byte number</i>&gt;,
&lt;<i>line</i>&gt;number
</pre>
</code>
<p>
When the
<b>-l</b>
option is used, the format is:
<p><code>
<pre>
<tt>"%d %o %o\n"</tt>, &lt;<i>byte number</i>&gt;,
&lt;<i>differing byte</i>&gt;,
&lt;<i>differing byte</i>&gt;
</pre>
</code>
for each byte that differs.
The first
&lt;<i>differing byte</i>&gt;
number is from
<i>file1</i>
while the second is from
<i>file2</i>.
In both cases,
&lt;<i>byte&nbsp;number</i>&gt;
is relative to the beginning of the file, beginning with 1.
<p>
No output will be written to standard output when the
<b>-s</b>
option is used.
</blockquote><h4><a name = "tag_001_014_102">&nbsp;</a>STDERR</h4><blockquote>
Used only for diagnostic messages.
If
<i>file1</i>
and
<i>file2</i>
are identical for the entire length of the shorter file,
in the POSIX locale
the following diagnostic message will be written, unless the
<b>-s</b>
option is specified:
<pre>
<code>
"cmp: EOF on %s%s\n", &lt;<i>name of shorter file</i>&gt;, &lt;<i>additional info</i>&gt;
</code>
</pre>
<p>
The
&lt;<i>additional info</i>&gt;
field is either null or a string that starts with a
blank character
and contains no
newline
characters.
Some systems report on the number of lines in this case.
</blockquote><h4><a name = "tag_001_014_103">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_104">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_105">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>The files are identical.

<dt>1<dd>The files are different;
this includes the case where one file is identical to the first part of
the other.

<dt>&gt;1<dd>An error occurred.

</dl>
</blockquote><h4><a name = "tag_001_014_106">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_107">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
Although input files to
<i>cmp</i>
can be any type, the results might not be
what would be expected on character special device files or on file
types not described by the <b>XSH</b> specification.
Since this specification does not specify the block size used when doing input,
comparisons of character special files need not compare all of
the data in those files.
</blockquote><h4><a name = "tag_001_014_108">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_109">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_110">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="comm.html">comm</a></i>,
<i><a href="diff.html">diff</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
